package cn.itcast.utils;

import cn.itcast.domain.system.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;


import java.io.IOException;
import java.io.InputStream;


public class WeiXinUtil {

	//公众号配置	
    public static final String APPID = "wxbcbf267fee301ca0";
    public static final String APPSECRET = "02299ed1d1fa59a0456df9c7805b6377";



    public String httpGet(String url){
        //创建httpclient对象
        HttpClient httpClient = new DefaultHttpClient();
        //创建Http get请求
        HttpGet httpGet = new HttpGet(url);
        //接收返回值
        HttpResponse response = null;
        String returnContent = "";
        try {
            //请求执行
            response = httpClient.execute(httpGet);
            if(response.getStatusLine().getStatusCode()==200){
                HttpEntity entity = response.getEntity();
                returnContent = EntityUtils.toString(entity, "UTF-8");
                System.out.println("--------->" + returnContent);
                /*JSONObject jsonObject = new JSONObject(content);
                openid = (String) jsonObject.get("openid");
                token = (String) jsonObject.get("access_token");
                System.out.println(openid);
                System.out.println(token);*/
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return returnContent;
    }

    public static void main(String[] args) {
        ObjectMapper mapper = new ObjectMapper();
        Module module = new Module();
        module.setId("1");

        try {
            String jsonString = mapper.writerWithDefaultPrettyPrinter()
                    .writeValueAsString(module);
            Module deserializedPerson = mapper.readValue(jsonString, Module.class);
            System.out.println(jsonString);
            System.out.println(deserializedPerson);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
